﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SftExaminer
{
    public partial class PackageHistoryForm : Form
    {
        private SinclairCC.AppV.ContentHeader cont;

        public PackageHistoryForm(SinclairCC.AppV.ContentHeader contentHeader)
        {
            InitializeComponent();

            this.cont = contentHeader;

            this.packageVersionsCombo.SuspendLayout();
            this.packageVersionsCombo.Items.Clear();
            foreach (SinclairCC.AppV.HistoryEntry he in contentHeader.HistoryEntries)
            {
                this.packageVersionsCombo.Items.Add(he);

                /*

                if (he is SinclairCC.AppV.HistoryEntry45)
                {
                    SinclairCC.AppV.HistoryEntry45 histEnt = he as SinclairCC.AppV.HistoryEntry45;
                    this.packageVersionsCombo.Items.Add(string.Format("[{0:G}] {1} on {2}", he.ModifiedTimeStamp.ToLocalTime(), histEnt.SequencerAccountName, histEnt.SequencerHostName));
                }
                else if (he is SinclairCC.AppV.HistoryEntry4x)
                {
                    SinclairCC.AppV.HistoryEntry4x histEnt = he as SinclairCC.AppV.HistoryEntry4x;
                    this.packageVersionsCombo.Items.Add(string.Format("[{0:G}] {1} on {2}", he.ModifiedTimeStamp.ToLocalTime(), histEnt.SequencerAccountName, histEnt.SequencerHostName));
                }
                */
            }
            if (this.packageVersionsCombo.Items.Count > 0)
                this.packageVersionsCombo.SelectedIndex = 0;
            else
                this.packageVersionsCombo.SelectedIndex = -1;
            this.packageVersionsCombo.ResumeLayout();
        }

        private void SelectedHistoryEntryChanged(object sender, EventArgs e)
        {
            if (this.packageVersionsCombo.SelectedItem is SinclairCC.AppV.HistoryEntry45)
            {
                SinclairCC.AppV.HistoryEntry45 histEnt = this.packageVersionsCombo.SelectedItem as SinclairCC.AppV.HistoryEntry45;
                this.versionGuidLabel.Text = this.cont.VersionGuids[this.packageVersionsCombo.SelectedIndex].ToString();
                this.saveDateLabel.Text = string.Format("{0:F}", histEnt.ModifiedTimeStamp);

                // TODO: Put spaces in the save mode string.
                this.saveModeLabel.Text = histEnt.Save.ToString();
                this.sequencerVersionLabel.Text = histEnt.SequencerVersion.ToString();
                this.sequencingUserLabel.Text = histEnt.SequencerAccountName;
                this.sequencingComputerLabel.Text = histEnt.SequencerHostName;

                // TODO: Fill in Windows version information.
                //this.windowsVersionLabel.Text
                //this.windowsEditionLabel.Text = histEnt.

                this.packageUpgradeLabel.Text = histEnt.PackageWasUpgraded ? "Yes" : "No";
                this.remoteDesktopLabel.Text = histEnt.RemoteDesktop ? "Yes" : "No";
                this.terminalServicesLabel.Text = histEnt.TerminalServices ? "Yes" : "No";
                this.lastBootNormalLabel.Text = histEnt.LastBootNormal ? "Yes" : "No";
                this.dotNetFrameworkLabel.Text = histEnt.SequencerDotNetVersion.Length > 0 ? histEnt.SequencerDotNetVersion : "not available";
                this.ieVersionLabel.Text = histEnt.SequencerInternetExplorerVersion.Length > 0 ? histEnt.SequencerInternetExplorerVersion : "not available";
                this.mediaPlayerVersionLabel.Text = histEnt.SequencerMediaPlayerVersion.Length > 0 ? histEnt.SequencerMediaPlayerVersion : "not available";
            }
            else if (this.packageVersionsCombo.SelectedItem is SinclairCC.AppV.HistoryEntry4x)
            {
                SinclairCC.AppV.HistoryEntry4x histEnt = this.packageVersionsCombo.SelectedItem as SinclairCC.AppV.HistoryEntry4x;
                this.versionGuidLabel.Text = this.cont.VersionGuids[this.packageVersionsCombo.SelectedIndex].ToString();
                this.saveDateLabel.Text = string.Format("{0:F}", histEnt.ModifiedTimeStamp);

                // TODO: Put spaces in the save mode string.
                this.saveModeLabel.Text = histEnt.Save.ToString();
                this.sequencerVersionLabel.Text = histEnt.SequencerVersion.ToString();
                this.sequencingUserLabel.Text = histEnt.SequencerAccountName;
                this.sequencingComputerLabel.Text = histEnt.SequencerHostName;

                // TODO: Fill in Windows version information.
                //this.windowsVersionLabel.Text
                //this.windowsEditionLabel.Text = histEnt.

                this.packageUpgradeLabel.Text = histEnt.PackageWasUpgraded ? "Yes" : "No";
                this.remoteDesktopLabel.Text = histEnt.RemoteDesktop ? "Yes" : "No";
                this.terminalServicesLabel.Text = histEnt.TerminalServices ? "Yes" : "No";
                this.lastBootNormalLabel.Text = histEnt.LastBootNormal ? "Yes" : "No";
                this.dotNetFrameworkLabel.Text = "Not available for this sequencer version.";
                this.ieVersionLabel.Text = "Not available for this sequencer version.";
                this.mediaPlayerVersionLabel.Text = "Not available for this sequencer version.";
            }
        }
    }
}
